package org.example.Servlet.pwd;

import cn.hutool.json.JSONUtil;
import org.example.utils.CodeUtil;
import org.example.utils.EmailUtil;

import javax.mail.MessagingException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/fw/sendEmail")
public class sendEmail extends HttpServlet {


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String email = req.getParameter("email");
        String code = CodeUtil.getCode();
        try {
            EmailUtil.sendVerificationCode(email, code);
            resp.getWriter().write(JSONUtil.toJsonStr(code));
        } catch (MessagingException e) {
            System.out.println("send code error ==> " + e.getMessage());
        }
    }
}
